package com.shrct.businessprocess.project;

import com.shrct.businessprocess.common.RCGeneralCreditData;
import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.project.IHasCreditStat;
import com.shrct.businessprocess.project.RCProjectCreditStatService;
import com.shrct.businessprocess.project.RCTotalProjectCreditStat;
import com.shrct.businessprocess.project.proxy.RCSalerCreditAdaptorProxy;
import edu.fudan.mylang.pf.EntityAdaptor;
import edu.fudan.mylang.pf.IGenericQuery;
import java.util.Collection;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.BeanFactory;

public class RCSalerCreditAdaptor extends EntityAdaptor<RCEmployee> implements IHasCreditStat {
  public RCSalerCreditAdaptor() {
    super();
  }
  
  public RCSalerCreditAdaptor(final RCEmployee adaptee) {
    this.adaptee = adaptee;
  }
  
  public RCSalerCreditAdaptorProxy toProxy() {
    return new RCSalerCreditAdaptorProxy(adaptee.toProxy());
  }
  
  public RCTotalProjectCreditStat getTotalProjectCreditStat() {
    RCTotalProjectCreditStat _xblockexpression = null;
    {
      IGenericQuery<RCGeneralCreditData> query=getObjectFactory().createGenericQuery(RCGeneralCreditData.class,"select new com.shrct.businessprocess.common.RCGeneralCreditData(e,saler.rate) from com.shrct.businessprocess.project.impl.RCProjectCreditStatImpl as e left join  e.project as p left join  p.salers as saler   where ((saler.employee) = (:adaptee)) and  e.active = 1      ").setParameter("adaptee",adaptee);
      final Collection<RCGeneralCreditData> stats = query.list();
      BeanFactory _beanFactory = this.getBeanFactory();
      RCProjectCreditStatService _bean = _beanFactory.<RCProjectCreditStatService>getBean(RCProjectCreditStatService.class);
      RCTotalProjectCreditStat _generateTotalStat = _bean.generateTotalStat(stats);
      final Procedure1<RCTotalProjectCreditStat> _function = new Procedure1<RCTotalProjectCreditStat>() {
          public void apply(final RCTotalProjectCreditStat it) {
            String _name = RCSalerCreditAdaptor.this.adaptee.getName();
            String _plus = (_name + "(");
            String _eid = RCSalerCreditAdaptor.this.adaptee.getEid();
            String _plus_1 = (_plus + _eid);
            String _plus_2 = (_plus_1 + ")");
            it.setTitle(_plus_2);
          }
        };
      RCTotalProjectCreditStat _doubleArrow = ObjectExtensions.<RCTotalProjectCreditStat>operator_doubleArrow(_generateTotalStat, _function);
      _xblockexpression = (_doubleArrow);
    }
    return _xblockexpression;
  }
}
